/*
    This file is part of libcloak.

    libcloak is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    libcloak is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with libcloak.  If not, see <http://www.gnu.org/licenses/>.

*/



#ifndef CLOAK_HANDLER
#define CLOAK_HANDLER


#include "Globals.h"
#include "Resource.h"
#include <boost/any.hpp>



	/* More macro hax
	   Use this to create the default constructor for a handler.
	   It just needs to pass a value it is given to the base class as a string
	   reference.

	   The easiest way of doing this is to just take a string (so the
	   const char* you are passing in 90%+ of the time gets a new string
	   constructed for it and passes that by reference to the base class).
	*/
	// Deprecated
	//#define CLOAK_HANDLER_CONSTRUCTOR(CLASS) CLASS(string path):Handler(path) {}

namespace Cloak
{

	typedef boost::any Entity;

	// Forward declaration.
	class Manager;

	// Used as handlers in the resource tree
	class Handler
	{


	private:
		/// The path that this handler is made to handle
		string path;
		bool wild;

	public:

		/// Create a new handler that can handle the given path name
		Handler(const string &path);
		virtual ~Handler();

		/// Get the path this can handle
		const string &getPath();
		bool isWild();

		/**
		 Handle a given path

		 This method must be overridden and replaced with the logic
		 required to create the element represented by the path
		 and attrs.

		 It should throw an exception if it is unable to complete the
		 request.

		 @param manager The Manager from which the request is coming.
		 @param path The path to be handled.
		 @param attrs The attribute map.

		 @return A pointer to any object you want. Return what is
		 most convenient for you, but it must be a pointer.
		 @warning Never reuse this resource, it will be deleted for you.
		 @warning This code must be thread-safe. Use mutexes if
		 necessary.
		 */
		virtual Entity handlePath(Manager &manager, PathVector &path, AttrMap &attrs) = 0;

	};

}

#endif
